import java.util.Scanner;
import java.util.Random;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        int total = 50; // 总题数
        int correct = 0; // 答对题数

        System.out.println("===== 100以内加减法口算练习（共50题）=====");

        for (int i = 1; i <= total; i++) {
            // 生成100以内随机数（0-99）
            int num1 = random.nextInt(100);
            int num2 = random.nextInt(100);
            // 随机判断运算类型：0为加法，1为减法（避免减法出现负数，交换num1和num2）
            boolean isAdd = random.nextBoolean();
            int result = 0;
            String operator = "";

            if (isAdd) {
                operator = "+";
                result = num1 + num2;
            } else {
                operator = "-";
                // 确保被减数 >= 减数，结果非负
                if (num1 < num2) {
                    int temp = num1;
                    num1 = num2;
                    num2 = temp;
                }
                result = num1 - num2;
            }

            // 输出题目并获取用户答案
            System.out.print("第" + i + "题：" + num1 + " " + operator + " " + num2 + " = ");
            int userAnswer = scanner.nextInt();

            // 判断对错并统计
            if (userAnswer == result) {
                System.out.println("正确！");
                correct++;
            } else {
                System.out.println("错误！正确答案是：" + result);
            }
        }

        // 计算正确率并输出结果
        double accuracy = (double) correct / total * 100;
        System.out.println("\n===== 练习结束 =====");
        System.out.println("总题数：" + total + " 题");
        System.out.println("答对题数：" + correct + " 题");
        System.out.printf("正确率：%.2f%%\n", accuracy);

        scanner.close();
    }
}